package com.fanyue.modules.wzb.mapper;

import com.fanyue.modules.wzb.entity.ClothingBatchEntity;
import com.fanyue.modules.wzb.entity.ClothingInfoEntity;
import com.fanyue.modules.wzb.vo.CountBatchVO;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 人员信息
 */
public interface ClothingBatchMapper extends BaseMapper<ClothingBatchEntity> {

    @Select("SELECT c.season,c.category,c.spec_id,s.name specName,\n" +
            "count(1) lendNum,\n" +
            "sum(if(bi.status = 1 or bi.status = 2, 1, 0)) revertNum,\n" +
            "sum(if(bi.status = 0, 1, 0)) awaitNum,\n" +
            "sum(if(bi.status = 2, 1, 0)) damageNum\n" +
            "FROM wzb_clothing_batch_item bi\n" +
            "LEFT JOIN wzb_clothing_info c on c.id = bi.clothing_id\n" +
            "LEFT JOIN wzb_clothing_spec s on s.id = c.spec_id\n" +
            "where bi.batch_id = #{batchId} and c.id is not null " +
            "GROUP BY c.season,c.category,c.spec_id")
    List<CountBatchVO> countByBatch(@Param("batchId") Long batchId);
}
